<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=UTF8" http-equiv="content-type">
<title>Simulation</title>
</head>
<body><%@page import="java.util.*"%>
	<%@page import="java.util.*"%>
	<%@page import="java.sql.*"%>
	<%@page
		import="hk.edu.cityu.is.riskmgmt.scheduler.*,hk.edu.cityu.is.riskmgmt.data.*"%>
	<%
		String simutype = request.getParameter("simutype");
		String lossrate = request.getParameter("loss_rate");
		String lossfreq = request.getParameter("lossfreq");
		String numberofbank = request.getParameter("numberofbank");
		String fxusd = request.getParameter("fxusd");
		String fxjpy = request.getParameter("fxjpy");
		String fxcny = request.getParameter("fxcny");
		String fxgbp = request.getParameter("fxgbp");
		String fxeur = request.getParameter("fxeur");
		String fxaud = request.getParameter("fxaud");
		String fxnzd = request.getParameter("fxnzd");
		String fxcad = request.getParameter("fxcad");

		String irusd = request.getParameter("irusd");
		String irjpy = request.getParameter("irjpy");
		String ircny = request.getParameter("ircny");
		String irgbp = request.getParameter("irgbp");
		String ireur = request.getParameter("ireur");
		String iraud = request.getParameter("iraud");
		String irnzd = request.getParameter("irnzd");
		String ircad = request.getParameter("ircad");

		String stocksp = request.getParameter("stocksp");
		String stockhsi = request.getParameter("stockhsi");
		String stockftse = request.getParameter("stockftse");
		String stocksh = request.getParameter("stocksh");
		String stocknikkie = request.getParameter("stocknikkie");
		String stockmsci = request.getParameter("stockmsci");

		String shockrate = request.getParameter("shock_rate");
		String pricing = request.getParameter("stockprice");
		String fxexp = request.getParameter("fxexp");
		String irexp = request.getParameter("irexp");
		String stockexp = request.getParameter("stockexp");
		String shockfreq = request.getParameter("shockfreq");

		String outflows = request.getParameter("outflows");
		String rsf = request.getParameter("rsf");

		//ArrayList al = new ArrayList();
		Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		String connectionUrl = "jdbc:sqlserver://localhost:1438;database=HKBANK;user=sa;password=1111";
		Connection conn = DriverManager.getConnection(connectionUrl);
		Statement stmt = conn
				.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
						ResultSet.CONCUR_UPDATABLE);
		String sql = "delete from configuration";
		String sql1 = "insert into configuration(numberofbank,fxusd,fxeur,fxgbp,fxcny,fxjpy,fxaud,fxnzd,fxcad,irusd,ircny,irjpy,ireur,irgbp,iraud,irnzd,ircad,shockrate,sp,hsi,ftse,sseci,msci,nikkei,fxexp,irexp,stockexp,shockfreq,lossrate,lossfreq, simutype,outflows,rsf) values(";
		String sql2 = numberofbank + "," + fxusd + "," + fxeur + ","
				+ fxgbp + "," + fxcny + "," + fxjpy + "," + fxaud + ","
				+ fxnzd + "," + fxcad + "," + irusd + "," + ircny + ","
				+ irjpy + "," + ireur + "," + irgbp + "," + iraud + ","
				+ irnzd + "," + ircad + "," + shockrate + "," + stocksp
				+ "," + stockhsi + "," + stockftse + "," + stocksh + ","
				+ stockmsci + "," + stocknikkie + "," + fxexp + "," + irexp
				+ "," + stockexp + "," + shockfreq + "," + lossrate + ","
				+ lossfreq + "," + simutype + "," + outflows + "," + rsf
				+ ")";
		System.out.println(sql1 + sql2);
		stmt.execute(sql);
		ResultSet rs = stmt.executeQuery(sql1 + sql2);
	%>
	<%
		new Thread() {
			public void run() {
				SharedData sd = new SharedData(); //sd.setBankno(Integer.parseInt(numberofbank));
				SimulationScheduler ss = new SimulationScheduler(sd);
				ss.start();
			}
		}.start();
	%>
	<script language="javascript">
		function fresh() {
			document.getElementById('table1').src = 'bigtable.jsp';
			setTimeout("fresh()", 1000);
		}
		setTimeout("fresh()", 1000);
		function changetodji() {
			document.getElementById('frame2').src = 'DJIChartApplet.jsp';
		}
		function changetohsi() {
			document.getElementById('frame2').src = 'HSIChartApplet.jsp';
		}
		function changetofti() {
			document.getElementById('frame2').src = 'FTSEChartApplet.jsp';
		}
		function changetocds() {
			document.getElementById('frame2').src = 'CDSChartApplet.jsp';
		}
		function changetolegend() {
			document.getElementById('frame2').src = 'legend.htm';
		}
		function changetotable() {
			document.getElementById('frame2').src = 'table.jsp';
		}
		function changetosh() {
			document.getElementById('frame2').src = 'SHChartApplet.jsp';
		}
		function changetonikkei() {
			document.getElementById('frame2').src = 'NikkeiChartApplet.jsp';
		}
		function changetobigtable() {
			document.getElementById('frame2').src = 'bigtable.jsp';
		}
		function changetolcr() {
			document.getElementById('frame2').src = 'lcr.jsp';
		}
		function changetonsfr() {
			document.getElementById('frame2').src = 'nsfr.jsp';
		}
		function changetolmi() {
			document.getElementById('frame2').src = 'lmi.jsp';
		}
		function changetocof() {
			document.getElementById('frame2').src = 'cof.jsp';
		}
		function changetolcrcurr() {
			document.getElementById('frame2').src = 'lcrcurr.jsp';
		}
		function changetoaua() {
			document.getElementById('frame2').src = 'aua.jsp';
		}
	</script>



	<table style="text-align: left; width: 100%;" border="1"
		cellpadding="2" cellspacing="2">
		<tbody>
			<tr>
				<td style="vertical-align: top;"><span
					style="font-weight: bold;">Chart</span><br>
				</td>
				<td colspan="2" rowspan="1"
					style="vertical-align: top; font-weight: bold;">Bank Risk
					Simulation Model<br>
				</td>
			</tr>
			<tr>
				<td colspan="1" rowspan="1" style="vertical-align: top;"><br>
				</td>
				<td colspan="2" rowspan="1"
					style="vertical-align: top; text-align: center; width: 50%;"><a
					href="javascript:changetodji();">S&P</a> | <a
					href="javascript:changetohsi();">HSI</a> | <a
					href="javascript:changetofti();">FTSE 100</a> | <a
					href="javascript:changetosh();">Shanghai</a> | <a
					href="javascript:changetonikkei();">Nikkei</a> | <a
					href="javascript:changetocds();">CDS</a> | <a
					href="javascript:changetolegend();">Legend</a> | <a
					href="javascript:changetolcr();">LCR</a> | <a
					href="javascript:changetonsfr();">NSFR</a> | <a
					href="javascript:changetolmi();">LMI</a>| <a
					href="javascript:changetocof();">CoF</a>| <a
					href="javascript:changetolcrcurr();">LCR by Currencies</a>| <a
					href="javascript:changetoaua();">Available unencumbered assets</a><br> <br>
				</td>
			</tr>
			<tr>
				<td style="vertical-align: top;"><applet
						code=hk.edu.cityu.is.riskmgmt.applets.CPVApplet.class
						archive="applets.jar,jfreechart-1.0.12.jar,jcommon-1.0.15.jar,sqljdbc.jar"
						width=500 height=300> </applet><br>
				</td>
				<td rowspan="1" colspan="2" style="vertical-align: top;"><iframe
						id="frame2" src="CDSChartApplet.jsp" height="400" width="800"></iframe>
				</td>

			</tr>
			<tr>
				<td colspan="1" rowspan="6" style="vertical-align: top;"><br>
					<table style="text-align: left; width: 504px; height: 111px;"
						border="1" cellpadding="2" cellspacing="2">
						<tbody>
							<tr>
								<td style="vertical-align: top;"><img
									src="https://chart.googleapis.com/chart?cht=p3&chd=t:<%=fxusd%>,<%=fxeur%>,<%=fxgbp%>,<%=fxjpy%>,<%=fxcny%>,<%=fxaud%>,<%=fxnzd%>,<%=fxcad%>&chs=250x150&chl=USD|EUR|GBP|JPY|CNY|AUD|NZD|CAD&chtt=FX" />
								</td>
								<td style="vertical-align: top;"><img
									src="https://chart.googleapis.com/chart?cht=p3&chd=t:<%=irusd%>,<%=ireur%>,<%=irgbp%>,<%=irjpy%>,<%=ircny%>,<%=iraud%>,<%=irnzd%>,<%=ircad%>&chs=250x150&chl=USD|EUR|GBP|JPY|CNY|AUD|NZD|CAD&chtt=Interest Rate" />
								</td>
								<td style="vertical-align: top;"><img
									src="https://chart.googleapis.com/chart?cht=p3&chd=t:<%=stocksp%>,<%=stockhsi%>,<%=stockftse%>,<%=stocksh%>,<%=stocknikkie%>,<%=stockmsci%>&chs=250x150&chl=S&P|HSI|FTSE|SH|Nikkei&chtt=Stock Exchange" /><br>
								</td>
							</tr>
						</tbody>
					</table> <br>
				</td>
				<td colspan="2" rowspan="1" style="vertical-align: top;"><span
					style="font-weight: bold;">Parameters &amp; Indictors</span><br>

				</td>

			</tr>
			<tr>
				<td style="vertical-align: top; font-weight: bold;"><iframe
						id="table1" src="bigtable.jsp" width="780" height="300"
						marginwidth="0" marginheight="0" scrolling="no" frameborder="0"></iframe><br>
				</td>
			</tr>
		</tbody>
	</table>

	<br>

</body>
</html>